package guitk;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JLabel;

@SuppressWarnings("serial")
public class IconedLabel extends JLabel {

	public static class SILabel {

		public String label;
		public String resource;

		public SILabel(String label, String resource) {
			this.label = label;
			this.resource = resource;
		}
	}

	protected List<SILabel> labels;

	protected IconedLabel(Builder b) {
		super();
		labels = b.labels;
		dimension = b.dimension;
	}

	Dimension dimension;

	public static class Builder {

		protected List<SILabel> labels;
		protected Dimension dimension;

		public Builder() {
			this.labels = new ArrayList<SILabel>();
		}

		public Builder add(String label, String resource) {
			labels.add(new SILabel(label, resource));
			return this;
		}

		public Builder setDimension(Dimension dim) {
			dimension = dim;
			return this;
		}

		public Builder setDimension(int x, int y) {
			dimension = new Dimension(x, y);
			return this;
		}

		public IconedLabel build() {
			return new IconedLabel(this);
		}
	}

	public void setStatus(String label) {
		for (SILabel si : labels)
			if (si.label.equalsIgnoreCase(label)) {
				setIcon(UI.getScaledIcon(dimension == null ? 24 : dimension.width, dimension == null ? 24 : dimension.height, si.resource));
			}
	}
}
